#include <iostream>
#include <algorithm>
#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <mutex>
#include <thread>
#include <chrono>
#include <benchmark/benchmark.h>
#include "src/TGLine.h"

std::once_flag flag;

int rand10() {
    std::call_once(flag, [](){srand(0);});
    return rand()%11;
}

TGPoint randPoint() {
    int x, y;
    x = rand10(); y = rand10();
    return {1.0*x, 1.0*y};
}

TGLine randLine() {
    TGLine l;
    l.data.first = randPoint();
    l.data.second = randPoint();
    return l;
}

//使用跨立实验来判断两线段是否有交点
static void bench_kuali(benchmark::State& state) {
    TGLine l1, l2;
    for(auto _ : state) {
        l1 = randLine(); l2 = randLine();
        bool flag = isIntersection(l1, l2);
    }
}

static void bench_kuali() {
    TGLine l1, l2;
    l1 = randLine(); l2 = randLine();
    bool flag = isIntersection(l1, l2);
}

BENCHMARK(bench_kuali);

//通过联立直线方程来进行交点求解
static void bench_parallel(benchmark::State& state) {
    TGLine l1, l2;
    for(auto _ : state) {
        l1 = randLine(); l2 = randLine();
        TGPoint p;
        bool flag = intersection(l1, l2, p);
    }
}

static void bench_parallel() {
    TGLine l1, l2;
    l1 = randLine(); l2 = randLine();
    TGPoint p;
    bool flag = intersection(l1, l2, p);
}

BENCHMARK(bench_parallel);

BENCHMARK_MAIN();


// int main() {
//     auto st = std::chrono::system_clock::now();
//     for(int i = 0; i < 100; i ++) {
//         bench_parallel();
//     }
//     auto ed = std::chrono::system_clock::now();
//     std::cout << std::chrono::duration_cast<std::chrono::microseconds>(ed-st).count() << std::endl;


//     st = std::chrono::system_clock::now();
//     for(int i = 0; i < 100; i ++) {
//         bench_paichi();
//     }
//     ed = std::chrono::system_clock::now();
//     std::cout << std::chrono::duration_cast<std::chrono::microseconds>(ed-st).count() << std::endl;

//     return 0;
// }